var rootview = ui("$");
var do_App = sm("do_App");
var do_Page = sm("do_Page");
var nf = sm("do_Notification");
var do_Global = sm("do_Global");

var activityUrl = require("url/activity");
var httpUrl = activityUrl.url.base.del;
var qqHttp = require("helper/http");
var helperOpen = require("helper/open");
//UI
var buttonDel=ui("buttonDel");
var layoutRoot=ui("layoutRoot");
var buttonSign=ui("buttonSign")
var buttonEdit=ui("buttonEdit");


rootview.setMapping({   // 此处的Mapping只能设置在 RootView 上 ;
	"layoutRoot.tag":"id",
    "activityTitle.text" : "name",
    "activityState.text" : "showStatus",
    "activityPrice.text" : "showCost",
    "activityImg.source" : "pathLogo",
    "activityAddr.text" : "address",
    "buttonSign.tag":"signCount"
});

rootview.on("dataRefreshed", function(){
	buttonSign.text="报名"+buttonSign.tag+"人";
});
buttonDel.on("touch",function(){
	nf.confirm("您确实要删除这条记录吗？", "删除", "确定", "取消", function(data, e) {
		if(data == 1){
			del();
		}
	})
});
buttonSign.on("touch",function(){
	helperOpen.open("source://view/activity/manage/sign/main.ui",{activityId:layoutRoot.tag});
})
function del(){
	var params = {
		id: layoutRoot.tag
	};
	qqHttp.post(httpUrl, params, function(data) {
		nf.toast("删除成功");
		do_Page.fire("deleteActivity",layoutRoot.tag);
	})
}
buttonEdit.on("touch",function(){
	if(buttonSign.tag>0){
		nf.toast("活动已经有人报名，无法编辑。");
		return;
	}
	helperOpen.open("source://view/activity/edit/main.ui",{activityId:layoutRoot.tag});
})